<?php
namespace Modules\Admin\Service;

class TemplateService{
	public function getAllTemplate(){
		$templates = glob (public_path ('/templates/*'));
		$configs = [];
		foreach ($templates as $v){
			if ($config = $this->parseConfig($v)){
				$configs[] = $config;
			}
		}
		return $configs;
	}
	public function parseConfig($dir){
		$package = $dir . '/package.json';
		if (is_file ($package)){
			$config = file_get_contents ($package);
			$config = json_decode ($config,true);
			$config['preview'] = asset ('/templates/' .basename ($dir) . '/' .$config['preview']);
			$config['name'] = basename ($dir);
			return $config;
		}
	}
}
?>